package com.ruoyi.web.controller.cs;

import java.util.List;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BasicsController;
import com.ruoyi.common.core.domain.Response;
import com.ruoyi.common.core.page.ResponsePageInfo;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cs.domain.TNotice;
import com.ruoyi.cs.service.ITNoticeService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公告信息Controller
 * 
 * @author ruoyi
 * @date 2021-03-25
 */
@Api(tags = {"公告信息管理"})
@RestController
@RequestMapping("/cs/notice")
@SuppressWarnings("ALL")
public class TNoticeController extends BasicsController
{
    @Autowired
    private ITNoticeService tNoticeService;

    /**
     * 后台查询公告信息列表
     * @param tNotice
     * @return
     */
    @ApiOperation("后台查询公告信息列表")
    @RequestMapping(name="后台查询公告信息列表",value="listBack",method = RequestMethod.POST)
    @PreAuthorize("@ss.hasPermi('cs:notice:listBack')")
    public ResponsePageInfo<TNotice> listBack(@RequestBody  TNotice tNotice)
    {
        startPage(tNotice.getPageNum(),tNotice.getPageSize());
        tNotice.setBackStage(Constants.BACKSTAGE);
        List<TNotice> list = tNoticeService.selectTNoticeList(tNotice);
        return toResponsePageInfo(list);
    }

    /**
     * 新增公告信息
     */
    @PreAuthorize("@ss.hasPermi('cs:notice:add')")
    @ApiOperation("新增公告信息")
    @RequestMapping(name="新增公告信息",value="add",method = RequestMethod.POST)
    @Log(title = "公告信息", businessType = BusinessType.INSERT)
    public Response<Integer> add(@RequestBody TNotice tNotice)
    {
        return toResponse(tNoticeService.insertTNotice(tNotice));
    }

    /**
     * 修改公告信息
     */
    @PreAuthorize("@ss.hasPermi('cs:notice:edit')")
    @ApiOperation("修改公告信息")
    @RequestMapping(name="修改公告信息",value="edit",method = RequestMethod.POST)
    @Log(title = "公告信息", businessType = BusinessType.UPDATE)
    public Response<Integer> edit(@RequestBody TNotice tNotice)
    {
        return toResponse(tNoticeService.updateTNotice(tNotice));
    }

    /**
     * 删除公告信息
     */
    @PreAuthorize("@ss.hasPermi('cs:notice:remove')")
    @ApiOperation("删除公告信息")
    @RequestMapping(name="删除公告信息",value="remove",method = RequestMethod.GET)
    @Log(title = "公告信息", businessType = BusinessType.DELETE)
    @ApiImplicitParam(name = "ggIds",value = "需要删除的公告信息ID，多个用，分割" , dataType = "String", paramType = "query", required = false)
    public Response<Integer> remove(String ggIds)
    {
        if (StringUtils.isNotEmpty(ggIds)) {
            String[] ids = ggIds.split(",");
            return toResponse(tNoticeService.deleteTNoticeByIds(ids));
        }else{
            return Response.fail(Constants.FAILCODE,"参数不能为空!");
        }
    }

    /**-------------------------------------前台接口---------------------------------------------*/
    /**
     * 查询公告信息列表
     */
    @ApiOperation("web查询公告信息列表")
    @RequestMapping(name="查询公告信息列表",value="common/list",method = RequestMethod.GET)
    public Response<List<TNotice>> list()
    {
        TNotice tNotice = new TNotice();
        tNotice.setDelFlag(Constants.SUCCESS);
        List<TNotice> list = tNoticeService.selectTNoticeList(tNotice);
        return Response.success(list);
    }
}
